<?php
/* adminexport.php 2006-07-02 12:48:44
   Conference Registration - Registration for conferences - A XOOPS CMS Module
   Copyright (c) 2006 Kevin van Haaren, US
   URL:     http://www.superfantasmoworld.com/
   Contact: kevin@vanhaaren.net
 	
   XOOPS
   Copyright (c) 2000 XOOPS.org
   URL:     http://www.xoops.org/
    
   This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    
 */
 
//The next comment block is for PHPDocumentor
/**
 * Conference Registration - Registration for conferences
 * 
 * adminexport.php
 * Export registration data to csv
 * 
 * @author Kevin van Haaren (kevin@vanhaaren.net)
 * @copyright 2006 Kevin van Haaren, US
 * @package CONFREG
 * @subpackage Admin_Function
 * 
 */

/**
* Do all the declarations etc needed by an admin page
*/
include_once "exportheader.inc";

$cleanPost = cleanInput($_POST);
$submit = strtolower($cleanPost['submit']);
if ($submit == strtolower(_AM_CONFREG_EMAIL_RECEIPT)) {
	create_pdf($cleanPost);
} else {
	echo '<html><head><title>Error</title></head><body>';
	echo '<h3>Error in submit button</h3>';
	echo '<p>There was an error in the submit data, please contact the webmaster.</p>';
	echo '</body></html>';
}


function create_pdf($cleanPost) {
	global $xoopsDB;
	
	include_once ('../class/pdf/class.ezpdf.php');

	$confid = intval($cleanPost['confid']);
	$groupid = intval($cleanPost['groupid']);


	$pdf =& new Cezpdf('letter','portrait');
	$pdf->selectFont('../class/pdf/fonts/Helvetica.afm');

	$pdf->ezImage('images/logo.png','10','','none','left','');
	$pdf->ezText("Mid-Continent MicroStation Community\nPO Box 6845\nShawnee Mission, KS 66206-0845\nTax ID: 48-1213592\n\n",12,array('justification'=>'left'));


	$confHdl = $xoopsDB->query(	"SELECT title, location" .
							" FROM " . $xoopsDB->prefix("confreg_data") . " WHERE confid=$confid");
	$confData = $xoopsDB->fetchArray($confHdl);

	$pdf->ezText("\n<b>Receipt for " . $confData['title'] . "</b>\n",14,array('justification'=>'center'));

	$groupData = get_group_data($groupid);

	unset($companyTable);
	$companyTable[0] = array('type'=>'Company Name:','data' => $groupData['company']);

	$mailaddress = (empty($groupData['mailaddress1'])) ? ' ' : $groupData['mailaddress1'];
	$mailaddress .=(empty($groupData['mailaddress2'])) ? ' ' : "\n" . $groupData['mailaddress2'];
	$mailaddress .=($groupData['mailcity'] . $groupData['mailstate'] . $groupData['mailzip'] === '') ? ' ' : ("\n" . $groupData['mailcity'] . ', ' . $groupData['mailstate'] . ' ' . $groupData['mailzip']);
	$companyTable[1] = array('type'=>'Mailing Address:','data'=>$mailaddress);
	
	$companyTable[2] = array('type'=>'Billing Name:','data'=>($groupData['bill_fname'] . $groupData['bill_lname'] === '') ? ' ' : ($groupData['bill_fname'] . ' ' . $groupData['bill_lname']));
	$billaddress = (empty($groupData['billaddress1'])) ? ' ' : $groupData['billaddress1'];
	$billaddress .=($groupData['billcity'] . $groupData['billstate'] . $groupData['billzip'] === '') ? ' ' : ("\n" . $groupData['billcity'] . ', ' . $groupData['billstate'] . ' ' . $groupData['billzip']);
	$companyTable[3] = array('type'=>'Billing Address:','data'=>$billaddress);

	$companyTable[4] = array('type'=>'Confirmation E-Mail:','data'=>$groupData['confirm_email']);
	$companyTable[5] = array('type'=>'Pay By:','data'=>$groupData['paytype']);
	$companyTable[6] = array('type'=>'Total Cost:','data'=>((empty($groupData['total_cost'])) ? '$0.00' : dollarfy($groupData['total_cost'],2)));
	$companyTable[7] = array('type'=>'Amount Paid:','data'=>((empty($groupData['AmountPaid'])) ? '$0.00' : dollarfy($groupData['AmountPaid'],2)));
	
	$pdf->ezTable($companyTable,'','Company Information',array('showHeadings'=>0,'cols'=>array('type'=>array('justification'=>'right'),'data'=>array('justification'=>'left'))));
	
	$users = get_group_users($groupid);

	$i = 1;
	foreach ($users as $peopleData) {
		unset($peopleTable);
		$peopleTable[0]=array('type'=>'Name:','data'=>($peopleData['first_name'] . $peopleData['last_name'] === '') ? ' ' : ($peopleData['first_name'] . ' ' . $peopleData['last_name']));
		$peopleTable[1]=array('type'=>'TMC Number:','data'=>((empty($peopleData['tmc_num'])) ? ' ' : $peopleData['tmc_num']));
		$peopleTable[2]=array('type'=>'E-Mail:','data'=>((empty($peopleData['email'])) ? ' ' : $peopleData['email']));
		$peopleTable[3]=array('type'=>'Days Attending:','data'=>((empty($peopleData['days_attending'])) ? ' ' : $peopleData['days_attending']));

		$workshops = get_user_workshops($peopleData['userid']);
		$wcount = 1;
		foreach ($workshops as $wData) {
			$peopleTable[$wcount + 3]=array('type'=>'Workshop ' . $wcount . ':','data'=>((empty($wData['title'])) ? ' ' : $wData['title']));
		}
		$peopleTable[7]=array('type'=>'Cost This Person:','data'=>((empty($peopleData['cost'])) ? '$ 0.00' : dollarfy($peopleData['cost'],2)));

		if ($i % 2 == 0) {
			$pdf->ezSetDy(145);
			$pdf->ezTable($peopleTable,'',"Attendee: $i",array('xPos'=>'460','protectRows'=>'8','showHeadings'=>0,'cols'=>array('type'=>array('justification'=>'right'),'data'=>array('justification'=>'left'))));
		} else {
			$pdf->ezText("\n");
			$pdf->ezTable($peopleTable,'',"Attendee: $i",array('xPos'=>'150','protectRows'=>'8','showHeadings'=>0,'cols'=>array('type'=>array('justification'=>'right'),'data'=>array('justification'=>'left'))));
		}
		$i++;
	}

	$pdf->setEncryption('','',array('print'));
	$pdf->ezStream();

/* debug code
	$pdfcode = $pdf->output(1);
	$pdfcode = str_replace("\n","\n<br>",htmlspecialchars($pdfcode));
	echo '<html><body>';
	echo trim($pdfcode);
	echo '</body></html>';
*/

}

?>
